import { toPng } from 'html-to-image'
let thumbTimer = null
const createThumbTimer = function() { 
    thumbTimer = setInterval(createThumb,10000)
}  

const createThumb = function() {
    const targetElement = document.querySelector('body'); 
        toPng(document.querySelector('body'))
        .then(dataUrl => {
            uni.request({
                url: "http://localhost:9287/tpl/createThumb",
                method: 'POST',
                dataType: 'json',
                header: {
                    "content-type": "application/x-www-form-urlencoded",
                },
                data: {
                    dataUrl:dataUrl.split(',')[1],
                }
            })
        })
        .catch(error => {
            console.error(error);
        });
}

export default createThumbTimer;